<template>
  <div id="app">
    <router-view v-if="isRouterAlive" />
  </div>
</template>
<script lang="ts">
import { nextTick, ref, provide } from "vue";
export default {
  name: "App",

  setup() {
    const isRouterAlive = ref<boolean>(true);
    const reload = () => {
      isRouterAlive.value = false;
      nextTick(() => {
        isRouterAlive.value = true;
      });
    };
    provide("reload", reload);
    // const WS: any = inject("WS");

    // const initWebsocket = () => {
    //   if ("WebSocket" in window) {
    //     // console.log("您的浏览器支持 WebSocket!");
    //     // location.host
    //     const ws = new WebSocket(
    //       "ws://192.180.0.97:8099/nir-focus/websocket/splitScreen"
    //     );
    //     WS.setWS(ws);
    //     ws.onopen = function() {
    //       console.log("websocket连接成功");
    //     };

    //     ws.onclose = function() {
    //       // 关闭 websocket
    //       console.log("连接已关闭...");
    //       //断线重新连接
    //       setTimeout(() => {
    //         initWebsocket();
    //       }, 2000);
    //     };
    //   } else {
    //     // 浏览器不支持 WebSocket
    //     console.log("您的浏览器不支持 WebSocket!");
    //   }
    // };
    // initWebsocket();
    return { reload, isRouterAlive };
  }
};
</script>
<style lang="scss">
#app {
  font-family: "Microsoft YaHei", "Helvetica Neue", Helvetica, "PingFang SC",
    "Hiragino Sans GB", "微软雅黑", Avenir, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-width: 800px;
  height: 100vh;
  margin: 0;
  padding: 0;
  list-style: none;
}
</style>
